package com.byxy.controller;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.byxy.aspect.MyLog;
import com.byxy.entity.Line;
import com.byxy.service.LineService;

@RequestMapping(value = "/line")
@Controller
public class LineController {

	@Resource
	private LineService lineService;

	@RequestMapping(value = "add", method = RequestMethod.GET)
	public String add() {
		return "line/add";
	}

	@RequestMapping(value = "add", method = RequestMethod.POST)
	public String add(Line line) {
		lineService.save(line);
		return "redirect:/line/list";
	}

	@MyLog(desc = "删除")
	@RequestMapping(value = "delete", method = RequestMethod.GET)
	public String delete(int id) {
		lineService.delete(id);
		return "redirect:/line/list";
	}

	@MyLog(desc = "显示列表")
	@RequestMapping(value = "list", method = RequestMethod.GET)
	public String list(Model model) {
		model.addAttribute("list", lineService.listAll());
		return "line/list";
	}

	@MyLog(desc = "数据更新")
	@RequestMapping(value = "update", method = RequestMethod.GET)
	public String update(int id, Model model) {
		model.addAttribute("line", lineService.getById(id));
		return "line/update";
	}

	@MyLog(desc = "数据更新")
	@RequestMapping(value = "update", method = RequestMethod.POST)
	public String update(Line line) {
		lineService.update(line);
		return "redirect:/line/list";
	}
}
